// pages/campus-detail/campus-detail.js
Page({
  data: {
    campusInfo: {
      name: '',
      address: '',
      phone1: '',
      phone2: '',
      busRoute: '',
      mapLat: null,
      mapLng: null,
      floorGuide: null
    }
  },

  onLoad(options) {
    // 页面加载时执行
    console.log('院区详情页面加载');
    
    // 接收传递的院区信息
    if (options.campus) {
      const campus = JSON.parse(options.campus);
      this.setData({
        campusInfo: {
          name: campus.fullName || `惠仁医院-${campus.name || ''}`,
          address: campus.address,
          phone1: campus.phone1,
          phone2: campus.phone2,
          busRoute: campus.busRoute,
          mapLat: campus.mapLat,
          mapLng: campus.mapLng,
          floorGuide: campus.floorGuide || null
        }
      });
    }
  },

  // 拨打电话
  onCallPhone(e) {
    const phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone,
      success: () => {
        console.log('拨打电话成功');
      },
      fail: () => {
        wx.showToast({
          title: '拨打电话失败',
          icon: 'none'
        });
      }
    });
  },

  // 地图导航
  onMapNavigation() {
    const { mapLat, mapLng, name, address } = this.data.campusInfo;
    if (mapLat && mapLng) {
      wx.openLocation({
        latitude: Number(mapLat),
        longitude: Number(mapLng),
        name: name || '医院位置',
        address: address || ''
      });
    } else {
      wx.showToast({ title: '无有效的地图坐标', icon: 'none' });
    }
  },

  // 院内导航
  onHospitalNavigation() {
    // 跳转到楼层索引页面
    wx.navigateTo({
      url: '/pages/floor-index/floor-index'
    });
  }
});
